package com.example.controller;

import com.example.common.Result;
import com.example.model.DTO.OrderDTO;
import com.example.model.PO.Order;
import com.example.model.VO.OrderVO;
import com.example.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * 支付相关接口
 *
 * @author Ng
 */
@Slf4j
@RestController
@RequestMapping("/pay")
public class PayController {

    @Autowired
    private OrderService orderService;

    /**
     * 微信
     */
    @PostMapping("/wechat")
    public Result<OrderVO> wechat(@RequestBody OrderDTO orderDTO) {

        // Map<String, Integer> map = new HashMap<>();
        // map.put("id", Math.toIntExact(id));

        Order order = orderService.check(orderDTO);
        log.info(String.valueOf(order));

        OrderVO orderVO = OrderVO.builder()
                .id(order.getId())
                .name(order.getName())
                .build();

        return Result.success(orderVO);
    }
}
